#pragma once
#include <iostream>
#include <string>
#include <unistd.h>
#include <pthread.h>

class Mutex
{
private:
    pthread_mutex_t _mutex;
public:
    Mutex()
    {
        if(::pthread_mutex_init(&_mutex,nullptr) != 0)
        {
            std::cerr<<"初始化互斥锁失败"<<std::endl;
            exit(1);
        }
    }
    pthread_mutex_t* GetMutex()
    {
        return &_mutex;
    }
    void lock()
    {
        ::pthread_mutex_lock(&_mutex);
    }
    void unlock()
    {
        ::pthread_mutex_unlock(&_mutex);
    }
};